<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('外派月账单列表')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-selectpicker">
                                <label>客户：</label>
                                <select name="customerIds" class="selectpicker" data-none-selected-text="请选择" th:with="type=${@customDictService.selectDictCustomer()}" multiple>
                                    <option th:each="dict : ${type}" th:text="${dict.title}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li class="select-selectpicker">
                                <label>项目：</label>
                                <select name="projectIds" class="selectpicker" data-none-selected-text="请选择" th:with="type=${@customDictService.selectDictStaffingProject()}" multiple>
                                    <option th:each="dict : ${type}" th:text="${dict.title}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>项目人员：</label>
                                <input type="text" name="name"/>
                            </li>
                            <li>
                                <label>年月：</label>
                                <input type="text" name="billYear"  style="width: 80px;"/> -  <input type="text" name="billMonth"  style="width: 40px;"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-primary" onclick="initMonthBill()" shiro:hasPermission="erp:bill:calculate">
                    <i class="fa fa-hourglass-half"></i> 初始化
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="erp:bill:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="erp:bill:form">
                    <i class="fa fa-upload"></i> 导入考勤数据
                </a>
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-fixed-columns-js" />
     <th:block th:include="include :: select2-js" />
     <th:block th:include="include :: bootstrap-select-js" />
</body>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasAnyPermi('erp:bill:edit,erp:bill:form')}]];
        var removeFlag = [[${@permission.hasPermi('erp:bill:remove')}]];
        var calculateFlag = [[${@permission.hasPermi('erp:bill:calculate')}]];
        var prefix = ctx + "erp/bill";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/import",
                modalName: "外派月账单",
                sortName: 'id',
                sortOrder: "desc",
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                showFooter: true,
                headerStyle: headerStyle,
                footerStyle: footerStyle,
                onClickCell: onClickCell,
                fixedColumns: true,
                fixedNumber: 5,
                fixedRightNumber: 3,
                columns: [
                    [{
                        title: '基本信息',
                        colspan: 6,
                        align: 'center',
                    },{
                        title: '考勤信息',
                        colspan: 4,
                        align: 'center',
                    },{
                        title: '加班信息（小时数）',
                        colspan: 5,
                        align: 'center',
                    },{
                        title: '报销及其他',
                        colspan: 3,
                        align: 'center',
                    },{
                        title: '汇总信息',
                        colspan: 7,
                        align: 'center',
                    }],
                    [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'projectName',
                    title: '项目名称'
                },
                {
                    field: 'personName',
                    width: '60px',
                    title: '姓名'
                },
                {
                    field: 'billYear',
                    title: '年'
                },
                {
                    field: 'billMonth',
                    title: '月'
                },
                {
                    field: 'fullDayCount',
                    titleTooltip: '当月应出勤天数',
                    title: '全勤'
                },
                {
                    field: 'normalDayCount',
                    title: '出勤'
                },
                {
                    field: 'absentDayCount',
                    title: '缺勤'
                },
                {
                    field: 'workFee',
                    title: '工时费用',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].workFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'overtimeHour1',
                    title: '1倍'
                },
                {
                    field: 'overtimeHour2',
                    title: '1.5倍'
                },
                {
                    field: 'overtimeHour3',
                    title: '2倍'
                },
                {
                    field: 'overtimeHour4',
                    title: '3倍'
                },
                {
                    field: 'overtimeFee',
                    title: '加班费',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].overtimeFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'expenseFee',
                    title: '报销金额'
                },
                {
                    field: 'expenseRateFee',
                    title: '报销结算',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].expenseRateFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'otherFee',
                    title: '其他费用'
                },
                {
                    field: 'totalFee',
                    title: '总结算费用',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].totalFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'profitRate',
                    title: '利润率',
                    cellStyle: function (value, row, index){
                        if (value != 0) {
                            return {
                                css: {color: "blue",cursor: "pointer"}
                            }
                        }else
                        {
                            return {}
                        }

                    },
                    formatter: function(value, row, index) {
                        var num = value * 100;
                        return num.toFixed(2) + '%';
                    }
                },
                {
                    field: 'billedFee',
                    title: '已结算费用',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].billedFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'payedFee',
                    title: '已收费用',
                    footerFormatter:function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            sumBalance += parseFloat(value[i].payedFee);
                        }
                        return sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'expireTime',
                    title: '收款截止期'
                },
                {
                    field: 'profitExplain',
                    title: '利润算法',
                    visible: false,
                },
                {
                    title: '操作',
                    width: '170px',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + calculateFlag + '" href="javascript:void(0)" onclick="calculateProfit(\'' + row.id + '\')"><i class="fa fa-calculator"></i>毛利</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + calculateFlag + '" href="javascript:void(0)" onclick="calculate(\'' + row.id + '\')"><i class="fa fa-calculator"></i>计算</a>');

                        return actions.join('');
                    }
                }]]
            };
            $.table.init(options);
        });

        function headerStyle(column) {
            return {
                workFee: {
                    css: { 'font-weight': 'bolder'  }
                },
                overtimeFee: {
                    css: { 'font-weight': 'bolder'  }
                },
                expenseRateFee: {
                    css: { 'font-weight': 'bolder'  }
                }
            } [column.field]
        }

        function calculate(id) {
            $.modal.confirm('计算后会覆盖原有数据，是否确认要计算？',function (){
                $.modal.loading("计算中....");
                $.operate.post(prefix + '/calculate',{'id': id},function (){
                    $.modal.closeLoading();
                })
            });
        }

        function calculateProfit(id) {
            $.modal.loading("计算中....");
            $.operate.post(prefix + '/profit',{'ids': id},function (){
                $.modal.closeLoading();
            });
        }

        function initMonthBill(){
            $.modal.open('初始化月账单' ,prefix + "/init", 600, 350);
        }

        function footerStyle(column) {
            return {
                totalFee: {
                    css: { color: 'red'}
                }
            }[column.field]
        }

        function onClickCell(field, value, row, $element){
            if (field == 'profitRate' && value != 0){
                $.modal.alert(row.profitExplain);
            }
        }
    </script>

    <!-- 导入区域 -->
    <script id="importTpl" type="text/template">
        <form enctype="multipart/form-data" class="mt20 mb10">
            <div class="col-xs-offset-1">
                <input type="file" id="file" name="file"/>
                <div class="mt10 pt5">
                    <input type="checkbox" id="calculate" name="calculate" title="是否计算导入数据。" checked> 是否计算导入数据
                    <input type="checkbox" id="update" name="update" title="如果数据已经存在，更新这条数据。" checked> 如果数据已经存在，更新这条数据
                </div>
                <font color="red" class="pull-left mt10">
                    提示：仅允许导入“xls”或“xlsx”格式文件！
                </font>
            </div>
        </form>
    </script>
</body>
</html>